class Solution {
public:
    int mySqrt(int x) {
        if(x<1)
        {
            return 0;
        }
        int left=1;
        int right=x;
        long long cur=(long long)x*x;
        while(left<right)
        {
            long long mid=left+(right-left+1)/2;
            if(mid*mid==x)
            {
                return mid;
            }
            if(mid*mid>x)
            {
                right=mid-1;
            }
            if(mid*mid<x)
            {
                left=mid;
            }
        }
        return left;
    }
};
